import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $fn, $http, $Lazy } = window
// ===================================================================== Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const message 			= $Lazy.file(()=>import('@antd/message'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: [],
		pag: {},
		selectedKeys: [],
		forms : [
			{ label: '项目代码',  	name: 'kind_code'},
			{ label: '项目全称',  	name: 'kind_name'},
			{ label: '助记码',  		name: 'debit_code'},
			{ label: '项目分类',		name: 'category', 	type:'select', loading:true},
			{ label: '岗位',		name: 'project_id', type:'select', loading:true },
			{ label: '备注',  		name: 'memo'},
		],
	}
	query = {kind_status: '2', filter:'1'}
	model = {}
	act_id = ''
	
	open = (uuid) => {
		this.getSelect()
		this.modal.open()
		this.act_id = uuid
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({api:'gang_wei'}))
			// 回顾
			$fn.setRow(forms, 'category',  await f.project_classify)
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'kind-info/index',)
	
	// 表单
	cols = [
		{ title: '项目分类', 		dataIndex: 'category_name', 	width:80 },
		{ title: '项目代码', 		dataIndex: 'kind_code', 		width:80 },
		{ title: '项目名称', 		dataIndex: 'kind_name', 		width:250 },
		{ title: '项目属性', 		dataIndex: 'kind_type_name', 	width:100 },
		{ title: '检测方法', 		dataIndex: 'check_method_name', width:150 },
		{ title: '岗位', 			dataIndex: 'job_name', 			width:100 },
		{ title: '助记码', 			dataIndex: 'debit_code', 		width:80 },
		{ title: '价格', 			dataIndex: 'total_price', 		...$fn.table.num },
		{ title: '项目排序', 		dataIndex: 'sort', 				...$fn.table.num },
		{ title: '备注', 			dataIndex: 'memo', 				width:200 }
	]
		
	render(){
		return TableModal.call(this,{ title: '活动项目', labelWidth:'s7', width:'90%', height:'80%',onOk:(selectedKeys)=>{
			$http.submit(null, 'act-conf-marketing/bindkind', { param:{act_id: this.act_id, kind_ids: selectedKeys } }).then(data=>{
				message.then(f=>f.success('添加成功'))
				this.modal.close()
				this.props.onRefresh()
			})
		}})
	
	}
}

export default Index